<?php

namespace App\Events;

use Illuminate\Broadcasting\Channel;
use Illuminate\Queue\SerializesModels;
use Illuminate\Broadcasting\PrivateChannel;
use Illuminate\Broadcasting\PresenceChannel;
use Illuminate\Foundation\Events\Dispatchable;
use Illuminate\Broadcasting\InteractsWithSockets;
use Illuminate\Contracts\Broadcasting\ShouldBroadcast;

class TestBroadcastEvent implements ShouldBroadcast
{
//    use Dispatchable, InteractsWithSockets, SerializesModels;

    public $test;

    /**
     * 指定事件被放置在哪个队列上
     *
     * @var string
     */
    public $broadcastQueue = 'channel:test:broadcast';

    /**
     * Create a new event instance.
     *
     * @return void
     */
    public function __construct()
    {
        $this->test = [1,2,3,4,5];
    }

    /**
     * 事件的广播名称。
     *
     * @return string
     */
    public function broadcastAs()
    {
        return 'channel.test.broadcast';
    }

    /**
     * 指定广播数据
     *
     * @return array
     */
//    public function broadcastWith()
//    {
//        return ['id' => $this->user->id];
//    }

    /**
     * 指定广播需要满足的条件.
     *
     * @return bool
     */
//    public function broadcastWhen()
//    {
//        return $this->value > 100;
//    }

    /**
     * Get the channels the event should broadcast on.
     *
     * @return \Illuminate\Broadcasting\Channel|array
     */
    public function broadcastOn()
    {
        //队列执行时触发
        return new Channel('channel.test.broadcast');
    }
}